#include "udpServer.hpp"
#include <memory>
#include <iostream>
#include <optional>
#include "log.hpp"
#include "dist.hpp"
const std::string defualtFunc(const std::string& message){
    std::string str="Hello, ";
    str+=message;
    return str;
}

int main(int argc,char* argv[])
{
    if(argc != 2){
        std::cerr<<"Usage: "<<argv[0]<<" port"<<std::endl;
        return 1;
    }
    uint16_t port =std::stoi(argv[1]);
    MY::LOG_SCREEN_STRATEGY_ENABLE;
    std::unique_ptr<MY::dist>dist=std::make_unique<MY::dist>();
    dist->init();    
    // std::unique_ptr<MY::udpServer>server=std::make_unique<MY::udpServer>(port,defualtFunc);
    std::unique_ptr<MY::udpServer>server=std::make_unique<MY::udpServer>
    (port,[&dist](const std::string& sentence)->const std::string{
        std::optional<std::string>result=dist->translate(sentence);
        if(result){
            return result.value();
        }
        else{
            return std::string();
        }
    });
    server->start();
    return 0;
}